package com.hystrix.order.controller;

import com.hystrix.order.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
//@DefaultProperties(defaultFallback = "gobalErrorHandler")
public class OrderController {

    @Resource
    private PaymentHystrixService paymentHystrixService;


    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        return paymentHystrixService.payment_ok(id);
    }


//    @HystrixCommand(fallbackMethod = "paymentInfo_TimeoutHandler",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "15000")
//    })
    @GetMapping("/consumer/payment/hystrix/error/{id}")
//    @HystrixCommand
    public String paymentInfo_Timeout(@PathVariable("id") Integer id){
//        int age = 10/0;
        String result = paymentHystrixService.payment_timeout(id);
        return  result;
    }

    public String paymentInfo_TimeoutHandler(Integer id) {
        return "/(ToT)/我是消费者80，调用8001支付系统繁忙或者自己运行错误，请10秒钟后重新尝试、\t";
    }

    public String gobalErrorHandler(){
        return "全局异常处理方法";
    }
}
